# 存放app 相关的操作，如，打开，重启，关闭
from appium import webdriver

from lagou.appium_exercise4.pages.base_page import BasePage
from lagou.appium_exercise4.pages.main_page import MainPage


class App(BasePage):
    def start(self):
        if self.driver == None:
            print("driver is None")
            desired_caps = {}
            desired_caps['platformName'] = 'Android'
            desired_caps['platformVersion'] = '6.0'
            desired_caps['deviceName'] = 'mydevice'
            desired_caps['appPackage'] = 'com.tencent.wework'
            desired_caps['appActivity'] = '.launch.LaunchSplashActivity'
            desired_caps['noReset'] = 'true'
            self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
            self.driver.implicitly_wait(10)
        else:
            print("driver is not None")
            self.driver.launch_app()   # 复用driver，launch_app() 即启动页面，热启动
        return self  # 停留在当前页面

    def restart(self):
        pass

    def stop(self):
        self.driver.quit()

    def goto_main(self):
        # 入口
        return MainPage(self.driver)
